package org.nfyszny.zzzs.modules.schedule;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import org.nfyszny.zzzs.modules.constant.CertificateConstant;
import org.nfyszny.zzzs.modules.entity.ZzzsCertificate;
import org.nfyszny.zzzs.modules.mapper.ZzzsCertificateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;
import java.util.List;

public class CertificateSchedule {
    @Autowired
    private ZzzsCertificateMapper certificateMapper;


    @Scheduled(cron = "0 0 0 * * ? ")
    public void checkYearCertificate(){
        QueryWrapper<ZzzsCertificate> queryWrapper=new QueryWrapper<>();
        queryWrapper.le("expiration_time",new Date());
        List<ZzzsCertificate> list = certificateMapper.selectList(queryWrapper);

        if (list.size()!=0&&list!=null){
            list.forEach(item->{
                item.setCertificateType(CertificateConstant.CertificateStatus.SUSPENDED.getCode());
                certificateMapper.updateById(item);
            });
        }


    }
}
